package routing;

import geocoding.ALGOTrip;
import geocoding.Converter;
import geocoding.CustomNodes;
import graph.ALGOEdge;
import graph.ALGOGraph;
import graph.ALGOPlacemarkNode;

import java.util.ArrayList;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.overlay.OverlayItem;

import osm.OsmReader;
import urnav.example.com.R;
import urnav.example.com.URNavActivity;

public class Items {
	
	String TAG="URNav";
	final ArrayList<OverlayItem> newItems = new ArrayList<OverlayItem>();
	
//	Adds Facility- nodes to the Item- Overlay
	public ArrayList<OverlayItem> getItems(CustomNodes cn){
		
		Converter myConverter = new Converter();
		
		ArrayList<OverlayItem> items= new ArrayList<OverlayItem>();
		int j=0;
		for (int i=0; i<cn.getSize(); i++){
		
		double lat=cn.getDlati(i);
		double lng=cn.getDlongi(i);
		int lati=myConverter.convertDouble(lat);
		int longi=myConverter.convertDouble(lng);
		String name=cn.getOsmID(i);

		
		
		
//         Switches markers according to type of facility
//        if (cn.getEinrichtung(i)==true){
        	
        	items.add(new OverlayItem(name, String.valueOf(i), new GeoPoint(lati, longi)));	
//        	Log.i(TAG, "Typ: " + String.valueOf(cn.getEinrichtung_typ(i)));
        	
//        	if (cn.getEinrichtung_typ(i).equals("food")){
//        		items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.hamburger));
//        	}
//        	
//        	else if (cn.getEinrichtung_typ(i).equals("bus")){
//        		items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.haltestelle));
//        	}
//        	
//            else if (cn.getEinrichtung_typ(i).equals("library")){
//            	items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.books));	
//        	}
//        	
//            else if (cn.getEinrichtung_typ(i).equals("uni_facility")){
//            	items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.uni_logo));	
//        	}
//        	
//            else if (cn.getEinrichtung_typ(i).equals("shop")){
//            	items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.shop));	
//        	}
//        	
//        	else {
        	
          
        	items.get(j).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_hdpi));
        	
        j++;
//        }
//        else {
//        	items.get(i).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_empty));
//		}

		}
		return items;
	}

	public ArrayList<OverlayItem> getItems(ALGOTrip trip, ALGOGraph myGraph, CustomNodes cn, Converter myConverter){
		ArrayList<OverlayItem> items= new ArrayList<OverlayItem>();
		int i=0;
		for (ALGOEdge algoEdge : trip) {
			
			String name=((ALGOPlacemarkNode)myGraph.getNode(algoEdge.getSource())).getValue().getName();
			int id = cn.getPosition(name);
			int lati= myConverter.convertDouble(cn.getDlati(id));
			int longi= myConverter.convertDouble(cn.getDlongi(id));
	        items.add(new OverlayItem(name, "SampleDescription", new GeoPoint(lati, longi))); 
	
	        items.get(i).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_hdpi));
	

	        i++;
	        }
		return items;
		
	}

	public ArrayList<OverlayItem> getItems(Trip myTrip, ALGOGraph myGraph, CustomNodes cn){
		
		Converter myConverter = new Converter();
		
		ArrayList<OverlayItem> items= new ArrayList<OverlayItem>();
		for (int i=0; i<myTrip.getTripList().size(); i++){
			int id=myTrip.getTripItem(i);
			String name=cn.getOsmID(i);
			int lati=myConverter.convertDouble(cn.getDlati(id));
			int longi=myConverter.convertDouble(cn.getDlongi(id));
			items.add(new OverlayItem(name, "SampleDescription", new GeoPoint(lati, longi))); 
			
			
			if (cn.getSilent(i) == false){
				items.get(i).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_hdpi));
			}
			
			else {
				items.get(i).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.tiny));	
			}

		}
		return items; 
	}
	    
	public ArrayList<OverlayItem> getItems(int currentNodePosition, Trip myTrip, ALGOGraph myGraph, CustomNodes cn){
		Converter myConverter = new Converter();
		ArrayList<OverlayItem> items= new ArrayList<OverlayItem>();
		int count=0;
		
		for (int i=currentNodePosition; i<myTrip.getTripList().size(); i++){	
			int id=myTrip.getTripItem(i);
			
			String name=cn.getOsmID(i);
			
			int lati=myConverter.convertDouble(cn.getDlati(id));
			int longi=myConverter.convertDouble(cn.getDlongi(id));
			
			items.add(new OverlayItem(name, "SampleDescription", new GeoPoint(lati, longi))); 
			
			
			if (i==0) {
				items.get(count).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.start));
			}
			
			if (!(currentNodePosition==myTrip.getTripList().size()-1)) {
			if (id == myTrip.getTripItem(currentNodePosition+1)){
//				Log.i(TAG, "NNS TRUE");
				items.get(count).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_red_hdpi));
			}
			}

			
//			else if (id == myTrip.getTripItem(currentNodePosition)){
//				items.get(count).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.tiny));	
//			}
			
			else if (id == myTrip.getTripItem(myTrip.getTripList().size()-1)){
				items.get(count).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.finish));
			}
			
			else {
				items.get(count).setMarker(URNavActivity.actVar.getResources().getDrawable(R.drawable.ic_map_hdpi));
			}
			
			int nextNotSilent= myTrip.getNextNotSilent(cn, currentNodePosition);
			
			
			count ++;
		}
		return items; 
		
	}

}
